package net.qunzhi.modules.cms.controller;

import java.util.Arrays;
import java.util.List;

import net.qunzhi.common.utils.BaseQuery;
import net.qunzhi.common.annotation.SysLog;
import net.qunzhi.modules.cms.query.CompletionData;
import net.qunzhi.modules.cms.query.DailyRecordListQuery;
import net.qunzhi.modules.cms.query.DateInfoQuery;
import net.qunzhi.modules.cms.service.TbEquipmentService;
import net.qunzhi.modules.cms.vo.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import net.qunzhi.modules.cms.entity.TbFlowMeterEntity;
import net.qunzhi.modules.cms.service.TbFlowMeterService;
import net.qunzhi.common.utils.PageUtils;
import net.qunzhi.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * 获取的流量计数据
 *
 * @author zjr
 * @date 2021-09-10 15:48:00
 */
@Api(tags = "获取的流量计数据相关")
@RestController
@RequestMapping("cms/tbFlowMeter")
public class TbFlowMeterController {
    @Autowired
    private TbFlowMeterService tbFlowMeterService;
    @Autowired
    private TbEquipmentService tbEquipmentService;

    /**
     * 列表
     */
    @ApiOperation("日常抄表记录列表")
    @GetMapping("/recordList")
    @RequiresPermissions("cms:tbFlowMeter:recordList")
    public R recordList(DailyRecordListQuery query){
        DailyRecordListVO vo = tbEquipmentService.queryDailyRecordList(query);

        return R.ok().put("vo", vo);
    }

    @ApiOperation("各泵站数据结果")
    @GetMapping("/resultList")
    @RequiresPermissions("cms:tbFlowMeter:resultList")
    public R resultList(DailyRecordListQuery query){
        List<DataResultVO> vo = tbEquipmentService.queryDataResultList(query);

        return R.ok().put("vo", vo);
    }

    @ApiOperation("明细查看")
    @GetMapping("/detail")
    @RequiresPermissions("cms:tbFlowMeter:detail")
    public R detail(DateInfoQuery query){
        DetailVO vo = tbEquipmentService.queryDetailVO(query);

        return R.ok().put("vo", vo);
    }

    @ApiOperation("查看趋势图")
    @GetMapping("/trend")
    @RequiresPermissions("cms:tbFlowMeter:trend")
    public R trend(DateInfoQuery query){
        TrendVO vo = tbEquipmentService.queryTrendVO(query);

        return R.ok().put("vo", vo);
    }

//    @ApiOperation("测试获取电源状态")
//    @GetMapping("/testele")
//    public R testele(){
//        tbEquipmentService.getElectricTask();
//
//        return R.ok();
//    }

    /**
     * 列表
     */
    @ApiOperation("列表")
    @GetMapping("/list")
    @RequiresPermissions("cms:tbFlowMeter:list")
    public R list(BaseQuery query){
        PageUtils page = tbFlowMeterService.queryPage(query);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation("信息")
    @GetMapping("/info/{id}")
    @RequiresPermissions("cms:tbFlowMeter:info")
    public R info(@PathVariable("id") Long id){
		TbFlowMeterEntity tbFlowMeter = tbFlowMeterService.getById(id);

        return R.ok().put("tbFlowMeter", tbFlowMeter);
    }

    /**
     * 保存
     */
    @ApiOperation("保存")
    @SysLog("获取的流量计数据保存")
    @PostMapping("/save")
    @RequiresPermissions("cms:tbFlowMeter:save")
    public R save(@RequestBody TbFlowMeterEntity tbFlowMeter){
		tbFlowMeterService.save(tbFlowMeter);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @SysLog("获取的流量计数据修改")
    @PostMapping("/update")
    @RequiresPermissions("cms:tbFlowMeter:update")
    public R update(@RequestBody TbFlowMeterEntity tbFlowMeter){
		tbFlowMeterService.updateById(tbFlowMeter);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @SysLog("获取的流量计数据删除")
    @PostMapping("/delete")
    @RequiresPermissions("cms:tbFlowMeter:delete")
    public R delete(@RequestBody Long[] ids){
		tbFlowMeterService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
